package com.syh.jn.scm.service.impl.upstream.base;

import cn.redscarf.commons.util.other.ExtAssert;
import cn.redscarf.commons.util.validator.ValidationUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.upstream.entity.base.UpBusinessEntityExtGoodsInfo;
import com.syh.jn.scm.domain.upstream.repository.base.UpBusinessEntityExtGoodsInfoRepository;
import com.syh.jn.scm.dto.upstream.base.UpBusinessEntityExtGoodsInfoMto;
import com.syh.jn.scm.dto.upstream.base.UpBusinessEntityExtGoodsInfoSto;
import com.syh.jn.scm.dto.upstream.base.UpBusinessEntityExtGoodsInfoVo;
import com.syh.jn.scm.service.api.upstream.base.UpBusinessEntityExtGoodsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UpBusinessEntityExtGoodsInfoServiceImpl extends AbstractServiceImpl<UpBusinessEntityExtGoodsInfoSto, UpBusinessEntityExtGoodsInfoMto, UpBusinessEntityExtGoodsInfoVo, UpBusinessEntityExtGoodsInfo, Long> implements UpBusinessEntityExtGoodsInfoService {
  @Autowired
  private UpBusinessEntityExtGoodsInfoRepository upBusinessEntityGoodsExtCodeRepository;

  @Override
  protected AggregateRepository<UpBusinessEntityExtGoodsInfo, Long> getAggregateRepository() {
    return upBusinessEntityGoodsExtCodeRepository;
  }

  @Override
  public Long save(UpBusinessEntityExtGoodsInfoSto sto) {
    ExtAssert.notNull(sto, "对象为空");
    ValidationUtils.validate(sto);

    //新建扩展编码业务对象
    UpBusinessEntityExtGoodsInfo upBusinessEntityExtGoodsInfo = new UpBusinessEntityExtGoodsInfo(sto);

    //保存到数据库中去
    return upBusinessEntityGoodsExtCodeRepository.add(upBusinessEntityExtGoodsInfo);
  }

  @Override
  public void update(UpBusinessEntityExtGoodsInfoMto mto) {
    ExtAssert.notNull(mto, "对象为空");
    ValidationUtils.validate(mto);

    //根据id查找扩展编码信息
    UpBusinessEntityExtGoodsInfo goodsExtCode = upBusinessEntityGoodsExtCodeRepository.getById(mto.getId());
    goodsExtCode.modify(mto);

    upBusinessEntityGoodsExtCodeRepository.update(goodsExtCode);
  }

  @Override
  public void delete(Long id) {

  }
}
